﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using CSWriter;
using Microsoft.WindowsMobile.Forms;
using CommunityServerRest;
using System.IO;
using System.Reflection;
using CSWriter.Blogs;
using CameraCapture.Properties;

namespace CameraCapture {
	static class Program {
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[MTAThread]
		static void Main() {
			OpenEditorWithCapture();
		}

		private static void OpenEditorWithCapture() {
			try {
				Settings settings = Settings.Load();
				BlogService service = new BlogService(settings.ServiceCredentials);
				BlogManager manager = new BlogManager(service);

				CameraCaptureDialog capDlg = new CameraCaptureDialog();
				capDlg.Mode = CameraCaptureMode.Still;
				if (capDlg.ShowDialog() == DialogResult.OK) {

					//Crea un post personalizado
					Cursor.Current = Cursors.WaitCursor;
					BlogPostItem post = new BlogPostItem(Resources.CameraCaptureTitle, string.Format(Resources.CameraCaptureBody, DateTime.Now.Date.ToShortDateString()), new Attachment(capDlg.FileName));
					Editor editor = new Editor(manager, post, settings, true);
					Cursor.Current = Cursors.Default;
					Application.Run(editor);
				}
			} catch (FileNotFoundException) {
				MessageBox.Show(Resources.ConfigurationFileNotFound);
			}
		}
	}
}